package com.ly.lypopupwindowdemo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.BottomSheetDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.ly.lypopupwindowdemo.R;

import java.util.ArrayList;
import java.util.List;

public class MDStudyActivity extends AppCompatActivity {

    /**
     * app:backgroundTint - 设置FloatingActionButton背景颜色。
     * app:rippleColor - 设置FloatingActionButton点击时的背景颜色。
     * app:elevation - 默认状态下FloatingActionButton阴影大小。
     * app:pressedTranslationZ - 点击FloatingActionButton时的阴影大小。
     * app:fabSize - 设置FloatingActionButton大小，该属性有两个值，分别为normal和mini
     * app:layout_anchor - 设置锚点，以哪个控件为参照点设置位置。
     * app:layout_anchorGravity - 设置相对锚点的位置，值有 bottom、center、right、left、top等。
     * <p>
     * FloatingActionButton这个控件还是比较简单的继承自ImageView，可以直接当成ImageView来使用。
     *
     * @param savedInstanceState
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mdstudy);

    }

    public void TextEditLayout(View view) {

        //http://www.jianshu.com/p/1de8c7a3cd58//博客地址，太困了看不下去了

        startActivity(new Intent(MDStudyActivity.this, EditTextLayoutActivity.class));

    }

    public void onRecycleView(View view) {

        startActivity(NewRecycleViewActivity.class);
    }

    public void onCollapsingClick(View view) {
        startActivity(CollapsingToolbarActivity.class);
    }

    private void startActivity(Class c) {
        Intent intent = new Intent(this, c);
        startActivity(intent);
    }

    public void TabLayout1(View view) {
        startActivity(TabLayoutActivity1.class);
    }

    public void onGridRecycleView(View view) {
        startActivity(GridRecycleViewActivity.class);

    }

    public void onBottomSheet(View view) {

        /**
         * http://www.jianshu.com/p/de5f9cdfba56
         * http://www.jianshu.com/p/de5f9cdfba56
         * http://www.jianshu.com/p/de5f9cdfba56
         */
        //changeHeadPhoto();
        showListDialog();

    }

    private void showListDialog() {

        BottomSheetDialog dialog = new BottomSheetDialog(this);
        View dialogView = LayoutInflater.from(this).inflate(R.layout.listview_dialog, null);
        ListView listview = (ListView) dialogView.findViewById(R.id.listview);
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            list.add("item" + i);
        }
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, list);

        listview.setAdapter(adapter);

        dialog.setContentView(dialogView);
        dialog.show();
    }

    private void changeHeadPhoto() {

        final BottomSheetDialog dialog = new BottomSheetDialog(MDStudyActivity.this);
        View dialogView = LayoutInflater.from(MDStudyActivity.this)
                .inflate(R.layout.bottomsheetlayout, null);
        TextView tvTakePhoto = (TextView) dialogView.findViewById(R.id.tv_take_photo);
        TextView tvPhotoAlbum = (TextView) dialogView.findViewById(R.id.tv_photo_album);
        TextView tvCancel = (TextView) dialogView.findViewById(R.id.tv_cancel);

        tvTakePhoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MDStudyActivity.this, "拍照", Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });
        tvPhotoAlbum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MDStudyActivity.this, "拍照", Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });

        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.setContentView(dialogView);
        dialog.show();

    }

    public void onDetailDemo(View view) {

    }
}
